<?php
/**
* Abstract class to offer basic functions for the Atom class.
*This class implements the get/set features allowing the Atom class to support evolving attributes
*for future growth and hides the management of the Atom timestamp, which is the way the Engine knows
*when something has changed and things like menus or caches have to be updated.
*@package Atoms
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*/
abstract class AtomBase
{
	private $atom_vars = array();
	private $lastupdate = 0;
	/**
	* Get an Atom attribute. False will be default for not-existing attributes (support future growth).
	*@param string $attr Attribute name.
	*@return mixed
	*/
	final protected function Get( $attr )
	{
		return isset( $this->atom_vars[$attr] ) ? $this->atom_vars[$attr] : false;
	}
	/**
	* Set value for an attribute. Will update the lastupdate timestamp.
	*@param string $attr Attribute name
	*@param mixed $value Attribute value to set
	*/
	final protected function Set( $attr, $value )
	{
		if ( isset( $this->atom_vars[ $attr ] ) && ( $this->atom_vars[ $attr ] == $value ) )
			return;
		$this->atom_vars[ $attr ] = $value;
		$this->SetLastUpdate();
	}
	/**
	* Initialize the lastupdate timestamp with current time.
	*/
	protected function __construct()
	{
		$this->lastupdate = time();
	}
	/**
	* Get the lastupdate timestamp (in seconds).
	*@return int
	*/
	final public function GetLastUpdate()
	{
		return $this->lastupdate;
	}
	/**
	* Update the lastupdate timestamp with current time.
	*/
	final public function SetLastUpdate()
	{
		$this->lastupdate = time();
		AtomCache::SetModified();
	}
}
?>